package com.egu.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.UserRole;
import com.egu.service.UserRoleService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("userRole")
public class UserRoleController {

	@Autowired
	private UserRoleService userRoleService;

	@RequestMapping("listUI")
	public String listUI() {
		return "userRole/listUI";
	}

	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<UserRole> getList(@ModelAttribute(value = "param") PageParam param, UserRole userRole) {
		RequestPageVo<UserRole> vo = userRoleService.getList(param, userRole);
		return vo;
	}
	
	
	
	@RequestMapping("/getAllList")
	@ResponseBody
	public RequestResultVo<List<UserRole>> getAllList() {
		RequestResultVo<List<UserRole>> vo = userRoleService.getAllList();
		return vo;
	}
	
	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<UserRole> saveOrUpdate(UserRole userRole) {
		RequestResultVo<UserRole> result = new RequestResultVo<UserRole>();
		if (userRole != null) {
			return userRoleService.saveOrUpdate(userRole);
		} else {
			result.setSuccess(false);
		}
		return result;
	}
	
	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<UserRole> deleteDataById(
			@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<UserRole> result = new RequestResultVo<UserRole>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("数据库操作异常");
			return result;
		}
		result = userRoleService.deleteDataById(id);
		return result;
	}
	
	
	
}
